package com.zte.market.service.otherService.otherImpl;

import com.zte.login.service.UserService;
import com.zte.market.mapper.otherMapper.CProductMapper;
import com.zte.market.pojo.otherPojo.CProduct;
import com.zte.market.service.otherService.CProductService;
import com.zte.market.service.otherService.CTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品
 * @Auther: 许月
 * @Date: 2022/10/06/19:28
 */
@Service
public class CProductServiceImpl implements CProductService {

    @Autowired
    private CProductMapper cProductMapper;

    @Autowired
    private UserService userService;

    @Autowired
    private CTypeService cTypeService;


    /**
     * 通过商品 id 查询商品信息
     * @param productId
     * @return
     */
    @Override
    public CProduct getByProductId(Integer productId) {
        CProduct product = cProductMapper.queryByProductId(productId);
        //设置品牌信息
        product.setCType(cTypeService.getByTypeId(product.getTypeId()));
        //设置创建人信息
        product.setCreateUser(userService.getUserById(product.getCreateId()));
        return product;
    }


    /**
     * 通过商品类型id获取商品列表（目的：为了根据商品类型id得到所有的商品型号）
     * @param typeId
     * @return
     */
    @Override
    public List<CProduct> getByTypeId(Integer typeId) {
        List<CProduct> cProductList = cProductMapper.queryByTypeId(typeId);
        for (CProduct product : cProductList) {
            //设置品牌信息
            product.setCType(cTypeService.getByTypeId(product.getTypeId()));
            //设置创建人信息
            product.setCreateUser(userService.getUserById(product.getCreateId()));
        }
        return cProductList;
    }
}
